<?php
if(!defined('IN_IBEIKE')) {
	exit('Access Denied');
}

class table_common_threadtype extends common_table
{
	public function __construct() {

		$this->_table = 'city_threadtype';
		$this->_pk    = 'typeid';

		parent::__construct();
	}
//from table_forum_threadtype.php
	public function fetch_all_for_cache() {
		return DB::fetch_all("SELECT t.typeid AS sortid, tt.optionid, tt.title, tt.type, tt.unit, tt.rules, tt.identifier, tt.description, tt.permprompt, tv.required, tv.unchangeable, tv.search, tv.subjectshow, tt.expiration, tt.protect
			FROM ".DB::table('forum_threadtype')." t
			LEFT JOIN ".DB::table('forum_typevar')." tv ON t.typeid=tv.sortid
			LEFT JOIN ".DB::table('forum_typeoption')." tt ON tv.optionid=tt.optionid
			WHERE t.special='1' AND tv.available='1'
			ORDER BY tv.displayorder");
	}
	public function fetch_all_for_order($typeid = array()) {
		if(!empty($typeid)) {
			$where = ' WHERE '.DB::field('typeid', $typeid);
		}
		return DB::fetch_all("SELECT * FROM ".DB::table('forum_threadtype')." $where ORDER BY displayorder");
	}
	public function checkname($name) {
		return DB::result_first("SELECT typeid FROM %t WHERE name=%s", array($this->_table, $name));
	}
	public function fetch_all_by_typeid($typeid){
		if(!empty($typeid)&&$typeid){
			return DB::fetch_all('SELECT * FROM %t WHERE typeid=%s',array($this->_table,$typeid));//返回数组包含各个字段的值
		}
		return false;
	}
}
?>